package Arrays;

/**
 * 作者:hfj
 * 功能:7.整数反转
 * 日期: 2024/6/13 21:34
 */
public class NumbersReverse {
    public static void main(String[] args) {
        System.out.println(reverse(0));
    }

    public static int reverse(int x){

        String target = x + "";
        String notation = "";
        if (x < 0){
            notation = "-";
            target = target.substring(1);
        }

        StringBuilder result = new StringBuilder();
        for (int i = target.length() - 1; i >= 0; i--) {
            result.append(target.charAt(i));
        }

        try {
            return Integer.parseInt(notation + result);
        } catch (NumberFormatException e) {
            return 0;
        }
    }
}
